#!/bin/sh
cd ${0%/*} || exit 1    # Run from this directory

# Parse arguments for library compilation
. $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments

if [ ! -d "$ParaView_DIR" ]
then
    echo "    Warning: ParaView not found in $ParaView_DIR. Skipping."
    exit 0
fi

# Ensure CMake gets the correct C/C++ compilers
[ -n "$WM_CC" ] && export CC="$WM_CC"
[ -n "$WM_CXX" ] && export CXX="$WM_CXX"

wmake $targetType vtkPVblockMesh
wmake $targetType vtkPVFoam

if [ "$targetType" != "objects" ]
then
    if $WM_PROJECT_DIR/bin/tools/foamVersionCompare $ParaView_VERSION ge 5.7.0
    then
        (
            mkdir -p Make/$WM_OPTIONS > /dev/null 2>&1
            cd Make/$WM_OPTIONS
            cmake ../..
            make -j $WM_NCOMPPROCS
        )
    else
        (
            cd PVblockMeshReader
            mkdir -p Make/$WM_OPTIONS > /dev/null 2>&1
            cd Make/$WM_OPTIONS
            cmake ../..
            make -j $WM_NCOMPPROCS
        )
        (
            cd PVFoamReader
            mkdir -p Make/$WM_OPTIONS > /dev/null 2>&1
            cd Make/$WM_OPTIONS
            cmake ../..
            make -j $WM_NCOMPPROCS
        )
    fi
fi

# Remove the old $FOAM_LIBBIN/libvtkPV*.so libraries, so that they do not get
# linked in preference to the new $PV_PLUGIN_PATH/libvtkPV*.so libraries
rm -f $FOAM_LIBBIN/libvtkPV*

#------------------------------------------------------------------------------
